package cn.ekuma.epos.datalogic.define.dao.erp;

import java.util.List;

import cn.ekuma.data.dao.ViewDAO;

import com.openbravo.bean.erp.viewbean.CustomerStockCurrentInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.QBFBuilder;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.data.loader.StaticSentence;

public class CustomerStockCurrentInfoDAO extends ViewDAO<CustomerStockCurrentInfo> {

	private static String LIST_Sql="SELECT P.ID, CS.TAXID, CS.SEARCHKEY, CS.NAME, L.NAME ,A.DESCRIPTION,C.UNITS,C.VALIDITYDATE,C.CREATEDATE "
        + "FROM CUSTOMER_STOCKCURRENT C LEFT OUTER JOIN ATTRIBUTESETINSTANCE A ON  C.ATTRIBUTESETINSTANCE_ID=A.ID ,PRODUCTS P ,LOCATIONS L,CUSTOMERS CS  ";

	public CustomerStockCurrentInfoDAO(I_Session s) {
		super(s);
	}

	@Override
	public CustomerStockCurrentInfo readValues(DataRead dr,CustomerStockCurrentInfo obj) throws BasicException {
		if(obj==null)
			obj=new CustomerStockCurrentInfo();
		obj.setM_ID(dr.getString(1));
		obj.setTaxid(dr.getString(2));
		obj.setSearchkey(dr.getString(3));
		obj.setName(dr.getString(4));
		obj.setM_Location(dr.getString(5));
		obj.setAttrsetInsDesc(dr.getString(6));
		obj.setM_unit(dr.getDouble(7));
		obj.setValidityDate(dr.getTimestamp(8));
		obj.setCreateDate(dr.getTimestamp(9));
		return obj;
	}

	@Override
	public Class getSuportClass() {
		return CustomerStockCurrentInfo.class;
	}
	
	 @Override
	    public List<CustomerStockCurrentInfo> list(Object filter) throws BasicException {
	        return new StaticSentence(s,new QBFBuilder( LIST_Sql+ "WHERE C.PRODUCT=P.ID AND C.LOCATION=L.ID AND ?(QBF_FILTER)",new String[]{"P.ID", "C.UNITS"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.STRING,Datas.OBJECT, Datas.DOUBLE}), this).list(filter);
	    }
}
